home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / globaltrash.lha / Plasma.good.s < prev    next >
Encoding:
Text File  |  1993-03-16  |  11.3 KB  |  523 lines

  1. ***********************************************************
  2. * This is the plasma routine from the Silents demo
  3. * "Global Trash".  The original version of this code, which
  4. * should be included in this archive, was send to me via
  5. * e-mail by Mattias Myrberg (m92mmy@megrez.tdb.uu.se).
  6. *
  7. * The version of the source that you are now looking at was
  8. * fixed up (and optimized a little bit) by the Dancing Fool
  9. * of Epsilon.
  10. ***********************************************************
  11. * Includes
  12. ***********************************************************
  13.  
  14.         incdir    "DevpacAm:include/"
  15.         include    "exec/exec_lib.i"
  16.         include    "exec/execbase.i"
  17.         include    "graphics/gfxbase.i"
  18.         include    "graphics/graphics_lib.i"
  19.         include    "hardware/custom.i"
  20.         incdir    ''
  21.  
  22. ***********************************************************
  23. * Other Equates
  24. ***********************************************************
  25.  
  26. PAL        equ    0        ; 0 = NTSC, 1 = PAL
  27.  
  28. Bits        equ    352
  29. Scan        equ    44
  30.  
  31.  IFEQ    PAL
  32. Rasters        equ    263
  33.  ELSE
  34. Rasters        equ    290
  35.  ENDIF
  36.  
  37. Bpsize        equ    Rasters*Scan
  38.  
  39. ***********************************************************
  40. * Other Macros
  41. ***********************************************************
  42.  
  43. CALL        MACRO
  44.         jsr    _LVO\1(a6)
  45.         ENDM
  46.  
  47. BltWait:    Macro                Wait for blitter
  48. Bltbusy\@:    btst.b    #6,2(a6)
  49.         bne.b    Bltbusy\@
  50.         Endm
  51.  
  52. Sync:        Macro                Syncronizise
  53. Rastwait\@    move.l    4(a6),d0
  54.         and.l    #$1ff00,d0
  55.         lsr.l    #8,d0
  56.         cmp.w    #\1,d0
  57.         bne.b    Rastwait\@
  58.         Endm
  59.  
  60. ***********************************************************
  61.  
  62.         Section    Program,code
  63.  
  64. TakeSystem:    movea.l    4.w,a6        ; exec base
  65.         lea    $dff000,a5    ; custom chip base + 2
  66.  
  67.         lea    GraphicsName(pc),a1    ; "graphics.library"
  68.         moveq    #0,d0        ; any version
  69.         CALL    OpenLibrary    ; open it.
  70.         move.l    d0,gfx_base    ; save pointer to gfx base
  71.         movea.l    d0,a6        ; for later callls...
  72.  
  73.         move.l  gb_ActiView(a6),OldView    ; save old view
  74.  
  75.         move.w    #0,a1        ; clears full long-word
  76.         CALL    LoadView    ; Open a NULL view (resets display
  77.                     ;   on any Amiga)
  78.  
  79.         CALL    WaitTOF        ; Wait twice so that an interlace
  80.         CALL    WaitTOF        ;   display can reset.
  81.  
  82.         CALL    OwnBlitter    ; take over the blitter and...
  83.         CALL    WaitBlit    ;   wait for it to finish so we
  84.                     ;   can safely use it as we please.
  85.  
  86.         movea.l    4.w,a6        ; exec base
  87.         CALL    Forbid        ; kill multitasking
  88.  
  89.         bsr.w    GetVBR        ; get the vector base pointer
  90.         move.l    d0,VectorBase    ; save it for later.
  91.  
  92.         move.w    dmaconr(a5),d0    ; old DMACON bits
  93.         ori.w    #$8000,d0    ; or it set bit for restore
  94.         move.w    d0,OldDMACon    ; save it
  95.  
  96.         move.w    intenar(a5),d0    ; old INTEna bits
  97.         ori.w    #$c000,d0    ; or it set bit for restore
  98.         move.w    d0,OldINTEna    ; save it
  99.  
  100.         move.l    #$7fff7fff,intena(a5)    ; kill all ints
  101.         move.w    #$7fff,dmacon(a5)    ; kill all dma
  102.  
  103.         lea    BmapPtrs+2,a0
  104.         move.l    #Screen,d0
  105.         move.w    d0,4(a0)
  106.         swap    d0
  107.         move.w    d0,(a0)
  108.         move.l    #Screen+Bpsize,d0
  109.         move.w    d0,12(a0)
  110.         swap    d0
  111.         move.w    d0,8(a0)
  112.         move.l    #Screen+(Bpsize*2),d0
  113.         move.w    d0,20(a0)
  114.         swap    d0
  115.         move.w    d0,16(a0)
  116.         move.l    #Screen+(Bpsize*3),d0
  117.         move.w    d0,28(a0)
  118.         swap    d0
  119.         move.w    d0,24(a0)
  120.  
  121.         move.l    VectorBase,a0
  122.         move.l    $6c(a0),OldLevel3
  123.         move.l    #Level3,$6c(a0)
  124.         move.l    #Copperlist,$80(a5)    ; Our Copperlist
  125.         move.w    #0,$88(a5)
  126.         move.w    #$83c0,dmacon(a5)    ; Turn on cop,bitplane,blt
  127.         move.w    #$c020,intena(a5)    ; Allow interrupt
  128.  
  129.         bsr.w    Init            ; Initiation
  130.  
  131.         lea    Pattern1(pc),a6
  132.         bsr.w    Main
  133.         lea    Pattern2(pc),a6
  134.         bsr.w    Main
  135.         lea    Pattern3(pc),a6
  136.         bsr.w    Main
  137.         lea    Pattern4(pc),a6
  138.         bsr.w    Main
  139.         lea    Pattern5(pc),a6
  140.         bsr.w    Main
  141.         lea    Pattern6(pc),a6
  142.         bsr.w    Main
  143.         lea    Pattern7(pc),a6
  144.         bsr.w    Main
  145.         lea    Pattern8(pc),a6
  146.         bsr.w    Main
  147.  
  148. Wait:        btst.b    #6,$bfe001
  149.         bne.b    Wait
  150.  
  151.  
  152. RestoreSystem:    lea    $dff000,a5    ; custom chip base + 2
  153.  
  154.     ; You must do these in this order or you're asking for trouble!
  155.         move.l    #$7fff7fff,intena(a5)    ; kill all ints
  156.         move.w    #$7fff,dmacon(a5)    ; kill all dma
  157.         move.l    VectorBase,a0
  158.         move.l    OldLevel3,$6c(a0)
  159.         move.w    OldDMACon,dmacon(a5)    ; restore old dma bits
  160.         move.w    OldINTEna,intena(a5)    ; restore old int bits
  161.  
  162.         movea.l    OldView,a1    ; old Work Bench view
  163.         movea.l    gfx_base,a6    ; gfx base
  164.         CALL    LoadView    ; Restore the view
  165.         CALL    DisownBlitter    ; give blitter back to the system.
  166.  
  167.         move.l    gb_copinit(a6),$80(a5) ; restore system clist
  168.         movea.l    a6,a1
  169.         movea.l    4.w,a6        ; exec base
  170.         CALL    CloseLibrary
  171.  
  172.     ; there is no call to Permit() because it is implied by the return
  173.     ; to AmigaDOS! :^)
  174.         rts
  175.  
  176. GraphicsName:    GRAFNAME        ; name of gfx library
  177.         EVEN
  178.  
  179. ***********************************************************
  180.  
  181. Init:        lea    Copper(pc),a0
  182.         lea    Copperlist,a1        ; Copper
  183.  
  184.         move.l    (a0)+,d0
  185. Find_end:    move.l    d0,(a1)+
  186.         move.l    (a0)+,d0
  187.         bne.b    Find_end
  188.  
  189.         lea    6(a1),a0        ; Start of color setting
  190.         move.l    a0,Copcol
  191.         move.w    #Rasters-1,d7        ; No of Copper rasters
  192.         move.l    #$17b1fffe,d0        ; WAIT
  193. Fill_copper:    move.l    d0,(a1)+
  194.         addi.l    #$01000000,d0
  195.         move.l    #$1820000,(a1)+        ; move    
  196.         move.l    #$1840000,(a1)+
  197.         move.l    #$1860000,(a1)+
  198.         move.l    #$1880000,(a1)+
  199.         move.l    #$18a0000,(a1)+
  200.         move.l    #$18c0000,(a1)+
  201.         move.l    #$18e0000,(a1)+
  202.         move.l    #$1900000,(a1)+
  203.         move.l    #$1920000,(a1)+
  204.         move.l    #$1940000,(a1)+
  205.         move.l    #$1960000,(a1)+
  206.         move.l    #$1980000,(a1)+
  207.         move.l    #$19a0000,(a1)+
  208.         move.l    #$19c0000,(a1)+
  209.         move.l    #$19e0000,(a1)+
  210.         dbf    d7,Fill_copper
  211.         moveq    #-2,d7
  212.         move.l    d7,(a1)+
  213.         rts
  214.  
  215. Bit_pointer:    dc.w    0
  216.  
  217. ***********************************************************
  218. * Draw screen
  219. * a6 = pattern
  220.  
  221. Main:        lea    Bitplane0,a0        ; Screen planes
  222.         lea    Bitplane1,a1
  223.         lea    Bitplane2,a2
  224.         lea    Bitplane3,a3
  225.         move.l    (a6)+,a4        ; Bitmaps
  226.         lea    Cosinus(pc),a5        ; Cosinus
  227.         movem.w    (a6)+,d1-d4        ; Start values
  228.  
  229.         move.w    #Rasters-1,d6        ; No of scanlines
  230.         moveq    #7,d0            ; Bit
  231. Next_scan:    move.w    #Bits-1,d7        ; No of bits in one scan
  232.  
  233. Next_bit:    move.b    d0,Bit_pointer        
  234.  
  235.         move.w    (a5,d1.w),d5
  236.         addi.w    #$4000,d5
  237.         lsr.w    #7,d5            ; d5 = Cos(d1)
  238.  
  239.         move.w    (a5,d2.w),d0
  240.         addi.w    #$4000,d0
  241.         lsr.w    #7,d0
  242.         add.w    d0,d5            ; + Cos(d2)
  243.  
  244.         move.w    (a5,d3.w),d0
  245.         addi.w    #$4000,d0
  246.         lsr.w    #7,d0
  247.         add.w    d0,d5            ; + Cos(d3)
  248.  
  249.         move.w    (a5,d4.w),d0
  250.         addi.w    #$4000,d0
  251.         lsr.w    #7,d0
  252.         add.w    d0,d5            ; + Cos(d4)
  253.  
  254.         lsr.w    #1,d5
  255.         add.w    d5,d5
  256.  
  257. Plot_bit:    move.w    (a4,d5.w),d5        ; d5 = bitmap
  258.         move.b    Bit_pointer(pc),d0
  259.         bclr    d0,(a3)            ; Set or clear bits in all
  260.         btst    #3,d5            ; planes
  261.         beq.b    Plane2
  262.         bset    d0,(a3)
  263. Plane2:        bclr    d0,(a2)
  264.         btst    #2,d5
  265.         beq.b    Plane1
  266.         bset    d0,(a2)
  267. Plane1:        bclr    d0,(a1)
  268.         btst    #1,d5
  269.         beq.b    Plane0
  270.         bset    d0,(a1)
  271. Plane0:        bclr    d0,(a0)
  272.         btst    #0,d5
  273.         beq.b    Ready
  274.         bset    d0,(a0)
  275.  
  276. Ready:        subq.b    #1,d0
  277.         bpl.b    No_underflow
  278.  
  279.         addq.b    #8,d0            ; Perform calculations
  280.         addq.w    #1,a0            ; on bit #7
  281.         addq.w    #1,a1            ; in next byte
  282.         addq.w    #1,a2
  283.         addq.w    #1,a3
  284.  
  285. No_underflow:    add.w    (a6),d1
  286.         add.w    2(a6),d2
  287.         add.w    4(a6),d3
  288.         add.w    6(a6),d4
  289.  
  290.         move.w    #$1ffe,d5
  291.         and.w    d5,d1
  292.         and.w    d5,d2
  293.         and.w    d5,d3
  294.         and.w    d5,d4
  295.         dbf    d7,Next_bit
  296.  
  297.         sub.w    8(a6),d1
  298.         sub.w    10(a6),d2
  299.         sub.w    12(a6),d3
  300.         sub.w    14(a6),d4
  301.         and.w    d5,d1
  302.         and.w    d5,d2
  303.         and.w    d5,d3
  304.         and.w    d5,d4
  305.         dbf    d6,Next_scan
  306.         rts
  307.  
  308. ***********************************************************
  309.  
  310. Level3:        movem.l    d0-a6,-(sp)
  311.  
  312.         lea    $dff000,a6
  313.         move.w    #$8400,$96(a6)
  314.         movea.l    Copcol(pc),a0        ; Copper
  315.         lea    Cosinus(pc),a1
  316.         move.l    #Area,d3
  317.         move.w    #$1ffe,d0
  318.         move.w    #$4000,d1
  319.         moveq    #15-1,d7        ; 16 colors
  320.  
  321.         movem.w    Rgb(pc),d4-d6
  322.         addi.w    #20,d4
  323.         addi.w    #26,d5
  324.         addi.w    #-30,d6
  325.         and.w    d0,d4
  326.         and.w    d0,d5
  327.         and.w    d0,d6
  328.         movem.w    d4-d6,Rgb
  329.  
  330. Next_colreg:    addi.w    #36,d4
  331.         addi.w    #-30,d5
  332.         addi.w    #24,d6
  333.         and.w    d0,d4            ; 0-8192
  334.         and.w    d0,d5
  335.         and.w    d0,d6
  336.         movea.l    d3,a2
  337.         movea.l    d3,a3
  338.         movea.l    d3,a4
  339.  
  340.         move.w    (a1,d4.w),d2
  341.         add.w    d1,d2
  342.         lsr.w    #7,d2
  343.         lsl.w    #1,d2            ; d2 = 0-512
  344.         adda.w    d2,a2
  345.  
  346.         move.w    (a1,d5.w),d2
  347.         add.w    d1,d2
  348.         lsr.w    #7,d2
  349.         lsl.w    #1,d2
  350.         adda.w    d2,a3
  351.  
  352.         move.w    (a1,d6.w),d2
  353.         add.w    d1,d2
  354.         lsr.w    #7,d2
  355.         lsl.w    #1,d2
  356.         adda.w    d2,a4
  357.  
  358.         BltWait
  359.         move.l    #$8ffe4000,$40(a6)    ; D=(A+8)+(B+4)+C
  360.         move.l    #-1,$44(a6)
  361.         move.l    a3,$48(a6)        ; C => red
  362.         move.l    a4,$4c(a6)        ; B => green
  363.         move.l    a2,$50(a6)        ; A => blue
  364.         move.l    a0,$54(a6)        ; D => copper
  365.         move.l    #0,$60(a6)        ; Mod A,B,C = 0
  366.         move.l    #62,$64(a6)        ; Mod D = 62
  367.         move.w    #(Rasters*64)+1,$58(a6)
  368.         addq.w    #4,a0
  369.         dbf    d7,Next_colreg
  370.  
  371.         movem.l    (sp)+,d0-a6
  372.         move.w    #$7fff,$dff09c
  373.         rte
  374.  
  375. ***********************************************************
  376. * This function provides a method of obtaining a pointer to the base of the
  377. * interrupt vector table on all Amigas.  After getting this pointer, use
  378. * the vector address as an offset.  For example, to install a level three
  379. * interrupt you would do the following:
  380. *
  381. *        bsr    _GetVBR
  382. *        move.l    d0,a0
  383. *        move.l    $6c(a0),OldIntSave
  384. *        move.l    #MyIntCode,$6c(a0)
  385. *
  386. ***********************************************************
  387. * Inputs: none
  388. * Output: d0 contains vbr.
  389.  
  390. GetVBR:        move.l    a5,-(sp)        ; save it.
  391.         moveq    #0,d0            ; clear
  392.         movea.l    4.w,a6            ; exec base
  393.         btst.b    #AFB_68010,AttnFlags+1(a6); are we at least a 68010?
  394.         beq.b    .1            ; nope.
  395.         lea.l    vbr_exception(pc),a5    ; addr of function to get VBR
  396.         CALL    Supervisor        ; supervisor state
  397. .1:        move.l    (sp)+,a5        ; restore it.
  398.         rts                ; return
  399.  
  400. vbr_exception:
  401.     ; movec vbr,Xn is a priv. instr.  You must be supervisor to execute!
  402. ;        movec   vbr,d0
  403.     ; many assemblers don't know the VBR, if yours doesn't, then use this
  404.     ; line instead.
  405.         dc.l    $4e7a0801
  406.         rte                ; back to user state code
  407.  
  408. ***********************************************************
  409.  
  410. Copper:        dc.l    $008e1771
  411.         dc.w    $0090
  412.         dc.b    (($17+Rasters)&$ff),$d1
  413.         dc.l    $00920030,$009400d8    ; 46 bytes/raster
  414. BmapPtrs:    dc.l    $00e00000,$00e20000,$00e40000,$00e60000
  415.         dc.l    $00e80000,$00ea0000,$00ec0000,$00ee0000
  416. Sprite:        dc.l    $01200000,$01220000,$01240000,$01260000
  417.         dc.l    $01280000,$012a0000,$012c0000,$012e0000
  418.         dc.l    $01300000,$01320000,$01340000,$01360000
  419.         dc.l    $01380000,$013a0000,$013c0000,$013e0000
  420.         dc.l    $01800000
  421.         dc.l    $01004200
  422. Copend:        dc.l    0
  423.  
  424.  
  425. Pattern1:    dc.l    Col1
  426.         dc.w    7616,768,7040,960
  427.         dc.w    8,12,-4,-16
  428.         dc.w    8*Bits+12
  429.         dc.w    12*Bits-16
  430.         dc.w    -4*Bits+24
  431.         dc.w    -16*Bits-20
  432.  
  433. Pattern2:    dc.l    Col1
  434.         dc.w    200,468,2040,196
  435.         dc.w    6,-30,2,16
  436.         dc.w    6*Bits-12
  437.         dc.w    -30*Bits+16
  438.         dc.w    2*Bits-24
  439.         dc.w    16*Bits+20
  440.  
  441. Pattern3:    dc.l    Col1
  442.         dc.w    10,10,10,10
  443.         dc.w    2,8,16,32
  444.         dc.w    2*Bits-2
  445.         dc.w    8*Bits-8
  446.         dc.w    16*Bits-16
  447.         dc.w    32*Bits-32
  448.  
  449. Pattern4:    dc.l    Col1
  450.         dc.w    0,-20,40,-80
  451.         dc.w    2,2,2,2
  452.         dc.w    2*Bits-2
  453.         dc.w    2*Bits-2
  454.         dc.w    2*Bits-2
  455.         dc.w    2*Bits-2
  456.  
  457. Pattern5:    dc.l    Col1
  458.         dc.w    344,-100,346,2
  459.         dc.w    18,-2,58,8
  460.         dc.w    18*Bits-34
  461.         dc.w    -2*Bits-4
  462.         dc.w    58*Bits+24
  463.         dc.w    8*Bits-20
  464.         dc.l    -1
  465.  
  466. Pattern6:    dc.l    Col1
  467.         dc.w    0,0,0,0
  468.         dc.w    8,8,8,8
  469.         dc.w    8*Bits-8
  470.         dc.w    8*Bits+8
  471.         dc.w    8*Bits+8
  472.         dc.w    8*Bits-2
  473.  
  474. Pattern7:    dc.l    Col1
  475.         dc.w    344,-100,346,2
  476.         dc.w    10,-2,28,4
  477.         dc.w    10*Bits-18
  478.         dc.w    -2*Bits-2
  479.         dc.w    28*Bits+12
  480.         dc.w    4*Bits-10
  481.  
  482. Pattern8:    dc.l    Col1
  483.         dc.w    346,102,-368,104
  484.         dc.w    4,6,-32,-78
  485.         dc.w    4*Bits-24
  486.         dc.w    6*Bits+14
  487.         dc.w    -32*Bits-68
  488.         dc.w    -78*Bits-10
  489.  
  490. Copcol:        dc.l    0
  491. Rgb:        ds.w    3
  492. Cosinus:    incbin    'Plasma.dat'
  493.  
  494. ***********************************************************
  495.  
  496.         section    CopperBars,data_c
  497.  
  498.         include    'CopperBars.i'
  499.  
  500. ***********************************************************
  501.  
  502.         section    OldPointers_and_such,bss
  503.  
  504. gfx_base    ds.l    1        ; pointer to graphics base
  505. OldView        ds.l    1        ; old Work Bench view addr.
  506. VectorBase:    ds.l    1        ; pointer to the Vector Base
  507.  
  508. OldDMACon:    ds.w    1        ; old dmacon bits
  509. OldINTEna:    ds.w    1        ; old intena bits
  510. OldLevel3:    ds.l    1        ; old level 3 int ptr
  511.  
  512. ***********************************************************
  513.  
  514.         section    ScreensAndCopper,bss_c
  515.  
  516. Copperlist:    ds.b    64*1024
  517. Screen:        ds.b    Scan
  518. Bitplane0    ds.b    Bpsize
  519. Bitplane1    ds.b    Bpsize
  520. Bitplane2    ds.b    Bpsize
  521. Bitplane3    ds.b    Bpsize
  522.         END
  523.